package problem1004;

//1004.最大连续1的个数
//https://leetcode.cn/problems/max-consecutive-ones-iii/

class Solution {
    public int longestOnes(int[] nums, int k) {
        int n = nums.length;
        int count = 0, ret = 0;
        for(int i = 0, j = 0; j<n; j++) {
            if(nums[j] == 0) {
                count++;
            }
            while(count > k) {
                if(nums[i] == 0) count--;
                i++;
            }
            ret = Math.max(ret, j-i+1);
        }
        return ret;
    }
}